home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / boot / BlizKick.lha / BlizKick / Modules / ChipSaver.ASM < prev    next >
Assembly Source File  |  2000-09-04  |  6KB  |  268 lines

  1. ; FILE: Source:modules/ChipSaver.ASM          REV: 52 --- Copies chipmem to fast
  2.  
  3. ;
  4. ; ChipSaver patch for BlizKick
  5. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. ; This module copies chip memory to fast memory if  if RMB is pressed during
  7. ; reboot. Creates ExoticRipper compatible image ($100 -image).
  8. ;
  9. ; Suggested by Max Romanoff.
  10. ;
  11. ; V1.1 - 5th Aug 2000
  12. ; Fucked up if the module patch was installed inside ROM. Fixed.
  13. ;
  14. ; Written by Harry Sintonen.
  15. ; This source code is Public Domain.
  16. ;
  17.  
  18. ;FASTBUFHEAD_LEN EQU    256*1024        ;skip first 256K (prevent trashing)
  19. CHIPBEGSAVE_LEN    EQU    64*1024            ;save lenght (must be multiple of 64)
  20.  
  21.     incdir    "include:"
  22.     include    "exec/types.i"
  23.     include    "exec/libraries.i"
  24.     include    "exec/memory.i"
  25.  
  26.     include    "exec/execbase.i"
  27.  
  28.     include    "blizkickmodule.i"    ; Some required...
  29.  
  30.     SECTION    PATCH,CODE
  31. _DUMMY_LABEL
  32.     BK_PTC
  33.  
  34. ; Code is run with following incoming parameters:
  35. ;
  36. ; a0=ptr to ROM start (buffer)    eg. $1DE087B8
  37. ; a1=ptr to ROM start (ROM)    eg. $00F80000 (do *not* access!)
  38. ; d0=ROM lenght in bytes    eg. $00080000
  39. ; a2=ptr to _FindResident routine (will search ROM buffer for resident tag):
  40. ;    CALL: jsr (a2)
  41. ;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to resident name
  42. ;     OUT: d0=ptr to resident (buf) or NULL
  43. ; a3=ptr to _InstallModule routine (can be used to plant a "module"):
  44. ;    CALL: jsr (a3)
  45. ;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to module, d6=dosbase
  46. ;     OUT: d0=success
  47. ; a4=ptr to _Printf routine (will dump some silly things (errormsg?) to stdout ;-)
  48. ;    CALL: jsr (a4)
  49. ;      IN: a0=FmtString, a1=Array (may be 0), d6=dosbase
  50. ;     OUT: -
  51. ; d6=dosbase, a6=execbase
  52. ;
  53. ; Code should return:
  54. ;
  55. ; d0=true if succeeded, false if failed.
  56. ; d1-d7/a0-a6 can be trashed. a7 *must* be preserved! ;-)
  57.  
  58.     cmp.w    #37,($C,a0)        ;requires V37+ rom image
  59.     bhs.b    .cont
  60.     moveq    #0,d0
  61.     rts
  62.  
  63. .cont    moveq    #0,d7
  64.  
  65.     move.l    d0,-(sp)
  66.     bsr    FindBlizMemMid
  67.     move.l    d0,d1
  68.     move.l    (sp)+,d0
  69.     tst.l    d1
  70.     beq.b    .noblizmem
  71. ;    add.l    #FASTBUFHEAD_LEN,d1
  72.     lea    (_absdstp_1,pc),a5    ;fix chipbegsave buffer adr
  73.     move.l    d1,(a5)
  74.     lea    (_absdstp_2,pc),a5
  75.     move.l    d1,(a5)
  76.  
  77.     move.l    a0,a5
  78.     move.l    #$13FC0003,d1
  79.     move.w    #512-1,d2
  80. .findl    subq.w    #1,d2
  81.     beq.b    .badrom
  82.     addq.l    #2,a5
  83.     cmp.l    (a5),d1
  84.     bne.b    .findl
  85.  
  86.     move.l    a5,d1            ;d1=jump pos (buf)
  87.     moveq    #8,d3
  88.     add.l    d1,d3
  89.     sub.l    a0,d3
  90.     add.l    a1,d3            ;d3=return jump pos (rom)
  91.  
  92.     move.l    a0,-(sp)
  93.     move.l    d1,a0            ;copy original code
  94.     lea    (_instpos,pc),a5
  95.     move.l    (a0)+,(a5)+
  96.     move.l    (a0)+,(a5)+
  97.  
  98.     lea    (_jmpromp,pc),a0    ;fix returning jmp
  99.     move.l    d3,(a0)
  100.  
  101.     move.l    d1,a5            ;create jmp
  102.     move.w    #$4EF9,(a5)+
  103.     move.l    (sp)+,a0
  104.  
  105.     move.l    d0,d5
  106.     lea    (_copier_module,pc),a1
  107.     jsr    (a3)            ;call _InstallModule
  108.     move.l    d0,d1
  109.     move.l    d5,d0
  110.     tst.l    d1
  111.     beq.b    .nomod
  112.  
  113.     lea    (_name,pc),a1
  114.     jsr    (a2)            ;call _FindResident
  115.     tst.l    d0
  116.     beq.b    .nomod
  117.  
  118.     move.l    d0,a0
  119.     move.l    #_earlycode-_init,d0
  120.     add.l    (RT_INIT,a0),d0
  121.     move.l    d0,(a5)
  122.  
  123.     moveq    #1,d7
  124. .nomod
  125. .badrom
  126. .noblizmem    move.l    d7,d0
  127.     rts
  128.  
  129.  
  130. FindBlizMemMid    movem.l    d1-a6,-(sp)
  131.     moveq    #0,d1
  132.     jsr    (-$84,a6)        ;Forbid
  133.     lea    (MemList,a6),a5
  134.     lea    (4,a5),a4
  135. .scanloop    move.l    (a5),a5
  136.     cmp.l    a5,a4
  137.     beq.b    .notfound
  138.     move.w    (MH_ATTRIBUTES,a5),d0
  139.     and.w    #MEMF_CHIP!MEMF_FAST!MEMF_PUBLIC,d0    ;Public fast?
  140.     cmp.w    #MEMF_FAST!MEMF_PUBLIC,d0
  141.     bne.b    .scanloop
  142.     cmp.l    #$01000000,(MH_LOWER,a5)    ;32bit?
  143.     blo.b    .scanloop
  144.     move.l    (LN_NAME,a5),d0
  145.     beq.b    .found
  146.     move.l    d0,a2
  147.     move.l    (a2),d0
  148.     or.l    #$20202020,d0        ;To lowercase
  149.     cmp.l    #'bliz',d0
  150.     beq.b    .found
  151.     tst.b    (a2)            ;null name -> buggy AllocMem result test!
  152.     bne.b    .scanloop
  153. .found    move.l    (MH_LOWER,a5),d1
  154. .notfound    jsr    (-$8A,a6)        ;Permit
  155.     move.l    d1,d0            ;must set d0!!
  156.     beq.b    .exit
  157.  
  158.     move.l    (MH_UPPER,a5),d0
  159.     sub.l    d1,d0
  160.     lsr.l    #2,d0            ;add ¼th
  161.     add.l    d1,d0
  162.     and.w    #$FFF0,d0
  163.  
  164. .exit    movem.l    (sp)+,d1-a6
  165.     rts
  166.  
  167.     CNOP    0,4
  168. _copier_module
  169.  BK_MOD BKMF_SingleMode,_end,(RTF_COLDSTART)<<24+37<<16+NT_UNKNOWN<<8+104,_name,_idstr,_init
  170.  
  171. ; Singlemode on,
  172. ; COLDSTART module, requires KS V37.x or better, module type NT_UNKNOWN, priority 104.
  173. ; At priority 104 fastmem should be available.
  174.  
  175. _init    btst    #6,$BFE001        ;test LMB
  176.     beq    .sexit            ;if pressed don't copy
  177.     movem.l    d0-a6,-(sp)
  178.  
  179.     lea    $DFF000,a5
  180.     move.w    #$FFFF,($34,a5)        ;pin 9 to write mode! ($0C00)
  181.  
  182.     moveq    #1-1,d0            ; Wait for two vertical blankings
  183. .wait1    btst    #0,($5,a5)        ; (Could wait only 300 µs!)
  184.     bne.b    .wait1
  185. .wait2    btst    #0,($5,a5)
  186.     beq.b    .wait2
  187.     dbf    d0,.wait1
  188.  
  189.     btst    #10-8,($16,a5)        ;test RMB
  190.     bne    .exit            ;if not pressed don't copy
  191.  
  192.     move.l    (4).w,a6
  193.     move.l    (MaxLocMem,a6),d2
  194.  
  195.     move.l    d2,d0
  196.     move.l    #MEMF_FAST!MEMF_PUBLIC!MEMF_REVERSE,d1    ; buggy on pre-39
  197.     jsr    (-$C6,a6)        ;AllocMem
  198.     tst.l    d0
  199.     beq.b    .exit
  200.     move.l    d0,a2
  201.  
  202.     move.l    a2,a1
  203.  
  204.     lea    $0BAD0000,a0
  205. _absdstp_1    EQU    *-4
  206.     move.w    #CHIPBEGSAVE_LEN/8-1,d0
  207. .cscopy    move.l    (a0)+,(a1)+
  208.     move.l    (a0)+,(a1)+
  209.     dbf    d0,.cscopy
  210.  
  211.     lea    CHIPBEGSAVE_LEN,a0
  212.     move.l    d2,d0
  213.     sub.l    a0,d0
  214.  
  215.     lsr.l    #6,d0            ;/64
  216.     subq.l    #1,d0
  217.     move.l    d2,d7
  218.     moveq    #4*4,d6
  219. .copy    move.w    d0,($180,a5)
  220.     movem.l    (a0)+,d1-d4        ;16
  221.     movem.l    d1-d4,(a1)
  222.     add.l    d6,a1
  223.     movem.l    (a0)+,d1-d4        ;16
  224.     movem.l    d1-d4,(a1)
  225.     add.l    d6,a1
  226.     movem.l    (a0)+,d1-d4        ;16
  227.     movem.l    d1-d4,(a1)
  228.     add.l    d6,a1
  229.     movem.l    (a0)+,d1-d4        ;16
  230.     movem.l    d1-d4,(a1)
  231.     add.l    d6,a1
  232.     dbf    d0,.copy
  233.     move.l    d7,d2
  234.  
  235.     move.l    a2,$100.w
  236.     move.l    #$DEADBEEF,(a2)+
  237.     move.l    d2,(a2)+
  238.     clr.l    (a2)
  239.  
  240.     move.w    #0,($180,a5)
  241.  
  242. .exit    movem.l    (sp)+,d0-a6
  243. .sexit    rts
  244.  
  245. _earlycode    sub.l    a0,a0
  246.     lea    $0BAD0000,a1
  247. _absdstp_2    EQU    *-4
  248.     move.w    #CHIPBEGSAVE_LEN/8-1,d0
  249. .ecopy    move.l    (a0)+,(a1)+
  250.     move.l    (a0)+,(a1)+
  251.     dbf    d0,.ecopy
  252. _instpos    nop
  253.     nop
  254.     nop
  255.     nop
  256.     jmp    $0BAD0000        ;jmppos+10
  257. _jmpromp    EQU    *-4
  258.  
  259. _name
  260. _idstr    dc.b    'ChipSaver',0
  261.     CNOP    0,2
  262. _end
  263.  
  264.     SECTION    VERSION,DATA
  265.  
  266.     dc.b    '$VER: ChipSaver_PATCH 1.1 (5.8.00)',0
  267.  
  268.